/**
 * 
 */
package weibo4j.crawler;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;



import weibo4j.Weibo;

/**
 * @author longrui
 * 
 */
public class CrawlerMaster {
	public static boolean exitFlag = false;
	private UserInfoCrawler userCrawler;	
	//private CommentCrawler commentCrawler;
	//private StatusCrawler statusCrawler;
	private Weibo weibo;
	private int queueBufMaxLength;
	

	public CrawlerMaster(String id, String password, int queueBufMaxLength)
			throws SQLException {
		weibo = new Weibo(id, password);
		this.queueBufMaxLength = queueBufMaxLength;		
	}

	public void start() throws InterruptedException, Exception {
		// initialization	
		userCrawler = new UserInfoCrawler(weibo, queueBufMaxLength);		
		
		long seedId = 1197161814L; // 李开复的id: 1197161814
		userCrawler.init(seedId);		
		userCrawler.start();		
	}
	
	public CrawlerBase getMainCrawler(){
		return userCrawler;
	}


	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			if (args.length < 2) {
				System.out
						.println("You need to specify WeiboID/Password combination to crawler the data.");
				System.out
						.println("Usage: java weibo4j.crawler.CrawlerMaster ID Password queueBufMaxLength");
				System.exit(0);
			}
			CrawlerMaster cm = new CrawlerMaster(args[0], args[1],
					Integer.parseInt(args[2]));
			cm.start();
			
			Runtime.getRuntime().addShutdownHook(new CleanUpTool());
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

}
